﻿#include "EditorSimpleMessageNotificationItemView.h"
#include "EditorSimpleMessageNotificationItemViewModel.h"

#include "Asset/EditorDefaultPackage.h"
#include "Widgets/TextWidget.h"
#include "Widgets/ImageWidget.h"
#include "Widgets/EditorImageButton.h"
#include "Widgets/Positioners/HorizontalPositionerWidget.h"


void REditorSimpleMessageNotificationItemView::BindViewModel(TSharedObjectPtr<REditorNotificationItemViewModel> InViewModel)
{
    Super::BindViewModel(InViewModel);
    SimpleMessageViewModel = InViewModel;
}

void REditorSimpleMessageNotificationItemView::FillWidget(TSharedObjectPtr<RWidget> InParentWidget)
{
    //不需要添加背景，背景已在通知窗口中添加
    auto ItemRoot=NewWidget<RWidget>(InParentWidget);
    ItemRoot->Anchor.Fill(InParentWidget);

    // auto Layout=NewWidget<RHorizontalPositionerWidget>(ItemRoot);
    // Layout->Anchor.Fill(ItemRoot);
    // Layout->Padding=5.f;

    auto Icon=NewWidget<RImageWidget>(ItemRoot);
    Icon->X=5;
    Icon->Y=5;
    Icon->Width=20;
    Icon->Height=20;
    Icon->Image=SimpleMessageViewModel->GetIcon();

    auto Text=NewWidget<RTextWidget>(ItemRoot);
    Text->Text=SimpleMessageViewModel->GetMessage();
    Text->Anchor.LeftReference=Icon;
    Text->Anchor.LeftReferenceEdge=EHorizontalWidgetEdge::Right;
    Text->Anchor.LeftOffset=5;
    Text->Y=5;

    const float ButtonSize=20;
    const float ButtonSpace=5;
    auto Buttons=NewWidget<RHorizontalPositionerWidget>(ItemRoot);
    Text->Anchor.RightReference=Buttons;
    Text->Anchor.RightOffset=5;
    Text->Anchor.RightReferenceEdge=EHorizontalWidgetEdge::Left;

    Buttons->Anchor.RightReference=ItemRoot;
    Buttons->Anchor.RightOffset=5;
    Buttons->Width=ButtonSize;
    Buttons->Height=ButtonSize;
    Buttons->Y=5;

    auto CloseButton = WHE::CreateImageButton(
        REditorDefaultPackage::Get()->GetIcon(U"CodiconClose")
        ,CString(U"清除通知(未实现)")
        ,[this]()
        {
            SimpleMessageViewModel->Remove();
        }
        ,Buttons
        ,ButtonSize
        ,ButtonSize
        );

}
